package com.leetcode;

import org.junit.Test;
import java.util.HashMap;
/**
 * Created by Z-hong on 2022/9/17.
 */

public class LeetCode1624 {
    public int maxLengthBetweenEqualCharacters(String s) {
        int len = -1;
        HashMap<Character, Integer> map = new HashMap<>();
        char[] arr = s.toCharArray();
        for (int i = 0; i < arr.length; i++) {
            if (map.containsKey(arr[i])){
                len=Math.max(len, i-map.get(arr[i])-1);
            }else {
                map.put(arr[i],i);
            }
        }
        return len;
    }

    @Test
    public void text(){
        int len=maxLengthBetweenEqualCharacters("aa");
        System.out.println(len);
    }
}
